package com.csq.portal.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.csq.cms.pojo.SeachParttime;
import com.csq.cms.service.ParttimeService;
import com.csq.common.pojo.ReturnResult;
import com.csq.common.pojo.StatusCode;
import com.csq.manager.pojo.Enterprise;
import com.csq.manager.pojo.Parttime;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/parttime")
public class ParttimeController {

	@Autowired
	private ParttimeService parttimeService;

	@RequestMapping(value = "/addParttime")
	public String addParttime(Parttime parttime, HttpServletRequest request) {

		ReturnResult returnResult = parttimeService.addParttime(parttime);

		if (returnResult.getState() != StatusCode.SUCCESS) {
			request.setAttribute("returnResult", returnResult);
			return "/web/error/index";
		}

		return "/web/company/parttimeList";

	}

	@RequestMapping(value = "/seach")
	public String getSeachParttime(@RequestParam String key, Integer page,
			Integer row, HttpServletRequest request) {

		PageInfo<SeachParttime> pageInfo = parttimeService.getSeachParttime(
				key, page, row);

		request.setAttribute("pageInfo", pageInfo);
		return "/web/parttime/seachResult";

	}

	@RequestMapping(value = "/{parttimeId}")
	public String getParttimeById(@PathVariable Integer parttimeId,
			Integer row, HttpServletRequest request) {
		Parttime parttime = parttimeService.getParttimeById(parttimeId);
		request.setAttribute("parttime", parttime);
		return "/web/parttime/parttimeDetail";

	}

	@RequestMapping(value = "/company/getParttimeList/{type}")
	public String getParttimeByEnterpriseId(@PathVariable Integer type,
			Integer page, Integer row, HttpServletRequest request) {

		Enterprise enterprise = (Enterprise) request.getSession().getAttribute("enterprise");
		
		
		System.out.println(enterprise);
		PageInfo<Parttime> parttimePageInfo = parttimeService.getParttimeByEnterpriseIdAndType(
				enterprise.getEnterpriseId(), type, page, row);
		request.setAttribute("parttimePageInfo", parttimePageInfo);
		
		return "/web/company/ParttimeList";

	}

}
